package Tool;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Test {

	/** 连接网站，模拟浏览器登陆，避免网站识别为手机进入 */
	private static final String USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0";

	/** 设置超时时间 */
	private static final int timeout = 50000;

	public static void main(String[] args) {
		try {
			String url = "http://gpj.mofcom.gov.cn/article/zt_mymcyd/subjectee/";
			url = "http://www.mofcom.gov.cn/article/ztxx/gwyxx/";
			Document doc = Jsoup.connect(url).userAgent(USERAGENT).timeout(timeout).get();
			//System.err.println(doc.html());
			Elements elements = doc.select(".MainList .listBox ul li:not(.listline)");
			if(elements!=null && elements.size()>0){
				for (Element e : elements) {
					System.out.println("标题："+e.select("a").attr("title"));
					System.out.println("地址："+e.select("a").attr("abs:href"));
					System.out.println("日期："+e.select("span").text());
					url = e.select("a").attr("abs:href");
					doc = Jsoup.connect(url).userAgent(USERAGENT).timeout(timeout).get();
					elements = doc.select(".MainList .article_new");
					if(elements!=null && elements.size()>0){
						for (Element e1 : elements) {
							System.out.println(new String("标题："+e1.select("#artitle").text()));
							System.out.println(new String("内容："+e1.select("#zoom").outerHtml()));
						}
					}
					break;
				}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
